package com.foreknow.elm.service.impl;

import com.foreknow.elm.dao.BusinessDao;
import com.foreknow.elm.dao.impl.BusinessDaoImpl;
import com.foreknow.elm.po.Business;
import com.foreknow.elm.service.BusinessService;
import com.foreknow.elm.util.DBUtil;

import java.util.ArrayList;
import java.util.List;

public class BusinessServiceImpl implements BusinessService {
    @Override
    public List<Business> listBusinessByOrderTypeId(Integer orderTypeId) {
        List<Business> list = new ArrayList<>();
        BusinessDao dao = new BusinessDaoImpl();
        try {
            DBUtil.getConnection();
            list = dao.listBusinessByOrderTypeId(orderTypeId);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            DBUtil.close();
        }
        return list;
    }
    /**
     * 根据商家编号查询商家信息
     * @param businessId
     * @return
     * @throws Exception
     */
    @Override
    public Business getBusinessById(Integer businessId){
        BusinessDao dao = new BusinessDaoImpl();
        Business bu = null;
        try {
            //获取链接
            DBUtil.getConnection();
            //调用多个Dao进行数据处理
            bu = dao.getBusinessById(businessId);
            //提交一个事务
//            DBUtil.commitTransaction();
        } catch(Exception e) {
            //回滚一个事务
            e.printStackTrace();
        } finally {
            // 关闭Connection
            DBUtil.close();
        }
        return bu;
    }
}
